package cool.taomu.toolkit.service.client.kademlia.module

import com.google.inject.AbstractModule
import com.google.inject.TypeLiteral
import com.google.inject.name.Names
import cool.taomu.toolkit.rpc.thrift.provider.TTransportPoolProvider
import cool.taomu.toolkit.service.client.kademlia.service.CheckPeerImpl
import cool.taomu.toolkit.service.client.kademlia.service.FindServiceImpl
import cool.taomu.toolkit.service.kademlia.provider.KBucketsModule
import cool.taomu.toolkit.service.kademlia.service.ICheckPeer
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import org.apache.thrift.transport.TTransport

class ServiceClientModule extends AbstractModule {

	override configure() {
		var pool = new TypeLiteral<GenericObjectPoolConfig<TTransport>>() {
		};
		bind(pool).annotatedWith(Names.named("taomu.kademlia.pool.config")).toProvider(TTransportPoolProvider).
			asEagerSingleton;
		bind(ICheckPeer).to(CheckPeerImpl).asEagerSingleton;
		bind(FindServiceImpl).asEagerSingleton
		install(new KBucketsModule)
	}
}
